package com.cskaoyan.controller.admin.mallcontroller;

import com.cskaoyan.bo.mallbo.CategoryCreateBo;
import com.cskaoyan.bo.mallbo.CategoryDeleteBo;
import com.cskaoyan.bo.mallbo.CategoryUpdateBo;
import com.cskaoyan.service.mallservice.CategoryService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.mallvo.CategoryCreateVo;
import com.cskaoyan.vo.mallvo.CategoryListVo;
import com.cskaoyan.vo.mallvo.Categoryl1Vo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hsp
 * @date 2021/5/10 11:17
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @RequiresPermissions("admin:category:list")
    @RequestMapping("list") //查看所有类目及子类目
    public BaseRespVo list(){

        List<CategoryListVo> categoryListVos = categoryService.list();

        return BaseRespVo.ok(categoryListVos);

    }


    @RequiresPermissions("admin:category:list")
    @RequestMapping("l1")   //返回一级类目的label和value
    public BaseRespVo l1(){
       List<Categoryl1Vo> categoryl1Vos =  categoryService.l1();
       return BaseRespVo.ok(categoryl1Vos);
    }
    /**
     *
     * @param categoryCreateBo
     * {"name":"测试类目-一级",
     * "keywords":"一级泪目关键词",
     * "level":"L1",
     * "pid":0,"
     * desc":"测试泪目简介",
     * "iconUrl":"http://localhost:8083/wx/storage/fetch/35623037396235652d34.jpg",
     * "picUrl":"http://localhost:8083/wx/storage/fetch/35613366313636392d32.jpg"}
     * @return
     */
    @RequiresPermissions("admin:category:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody CategoryCreateBo categoryCreateBo){

       CategoryCreateVo categoryCreateVo =  categoryService.createCategory(categoryCreateBo);
       return BaseRespVo.ok(categoryCreateVo);
    }

    @RequiresPermissions("admin:category:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody CategoryUpdateBo categoryUpdateBo){

        categoryService.updateCategory(categoryUpdateBo);

        return BaseRespVo.ok();
    }

    @RequiresPermissions("admin:category:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody CategoryDeleteBo categoryDeleteBo)
    {
        categoryService.logicDeleteCategory(categoryDeleteBo);

        return BaseRespVo.ok();
    }



}
